home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 412_01 / demos / demo4.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-28  |  1.8 KB  |  67 lines

  1. #include <stdio.h>
  2. #include "graph.h"
  3.  
  4.  
  5. /*                     DEMO4
  6.  
  7.     The object of this problem is the same as in demo3. The only difference
  8.     is in the search method used. In this problem we want to use the best
  9.     first algorithm and, therefore, derive class PUZZLE_ from class BEST_.
  10.     Because of this we need to implement the functions compute_g() and
  11.     compute_h() in PUZZLE_.
  12.  
  13. */ 
  14.  
  15.  
  16.  
  17. /*                       PNODE.H
  18.  
  19.     This class resembles class PNODE_ in demo3 except that it's derived
  20.     from class BEST_NODE_, instead of class NODE_. We derive it from this
  21.     class because we want to perform a best first search using class
  22.     BEST_ and this class processes (derivatives of) class BEST_NODE_.
  23.  
  24. */
  25.  
  26. class PNODE_ : public BEST_NODE_
  27. {
  28.     public:
  29.         PNODE_(const char *, int empty_x, int empty_y);
  30.         PNODE_(const char *, int, int, int, int);
  31.         int get_x() const;
  32.         int get_y() const;
  33.         const char (*get_board() const)[3];
  34.  
  35. // implementation of virtual functions
  36.         int equal(const VOBJECT_ &) const;
  37.         void display() const;
  38.         NODE_ *do_operator(int) const;
  39.     private:
  40.         PNODE_
  41.             *do_left() const,
  42.             *do_right() const,
  43.             *do_up() const,
  44.             *do_down() const;
  45.             int compare_board(const char [3][3]) const;
  46.         int
  47.             x,
  48.             y;
  49.         char
  50.             board[3][3];
  51. };
  52.  
  53.  
  54.  
  55. class PUZZLE_ : public BEST_
  56. {
  57.     public:
  58.         PUZZLE_(PNODE_ *start, PNODE_ *target);
  59.         int compute_g(const NODE_ &);
  60.         int compute_h(const NODE_ &);
  61.     private:
  62.         int totdist(const char [3][3], const char[3][3]);
  63.                        // computes manhatten distance
  64.     PNODE_ *goal;  // goal node, needed by totdist()
  65. };
  66.  
  67.